package com.java.comprehensive.design.behavioral_model.visitor_pattern.er;

/**
 * @Author 窦绍飞
 * @create 2023/3/2
 */
public class Animal {
	public void accept(Execute execute) {
		execute.execute(this);
	}
}

class Cat extends Animal {
	@Override
	public void accept(Execute execute) {
		execute.execute(this);
	}
}

class Dog extends Animal {
	@Override
	public void accept(Execute execute) {
		execute.execute(this);
	}
}

class Execute {
	public void execute(Cat cat) {
		System.out.println("cat");
	}

	public void execute(Animal animal) {
		System.out.println("animal");
	}

	public void execute(Dog dog) {
		System.out.println("dog");
	}
}

class Test {
	public static void main(String[] args) {
		Animal animal = new Animal();
		Animal d = new Dog();
		Animal c = new Cat();

		Execute execute = new Execute();
		execute.execute(animal);
		execute.execute(d);
		execute.execute(c);

		animal.accept(execute);
		d.accept(execute);
		c.accept(execute);
	}

}
